package com.acwing.lc.part1;

import java.io.*;

/**
 * @author rkc
 * @date 2022/9/5 14:37
 */
public class LC5最长回文子串_区间dp {

    private static final int N = 1010;
    private static boolean[][] f = new boolean[N][N];

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        writer.write(longestPalindrome(reader.readLine()));
        writer.flush();
    }

    public static String longestPalindrome(String s) {
        int l = 0, r = 0, maxl = 1;
        for (int i = 0; i < N; i++) f[i][i] = true;
        for (int len = 2; len <= s.length(); len++) {
            for (int i = 0; i <= s.length() - len; i++) {
                int j = i + len - 1;
                if (s.charAt(i) == s.charAt(j) && (len == 2 || f[i + 1][j - 1])) {
                    f[i][j] = true;
                    if (len > maxl) {
                        maxl = len;
                        l = i;
                        r = j;
                    }
                }
            }
        }
        return s.substring(l, r + 1);
    }
}
